export default {
  setCookie: function (name, value, expiremMinutes) {
    let exdate = new Date()
    exdate.setTime(exdate.getTime() + expiremMinutes * 60 * 1000)
    document.cookie = name + '=' + escape(value) + ((expiremMinutes === null) ? '' : ';expires=' + exdate.toGMTString())
  },
  getCookie: function (name) {
    if (document.cookie.length > 0) {
      let start = document.cookie.indexOf(name + '=')
      if (start !== -1) {
        start = start + name.length + 1
        let end = document.cookie.indexOf(';', start)
        if (end === -1) {
          end = document.cookie.length
          return unescape(document.cookie.substr(start, end))
        }
      }
    }
    return ''
  },
  delCookie: function (name) {
    let exp = new Date()
    exp.setTime(exp.getTime() - 1)
    let cval = this.getCookie(name)
    if (cval !== null) {
      document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString()
    }
  }
}
